Conversation
Video StoreWhat We're Looking For
|
| def checkout | ||
| rental = Rental.new(rental_params) | ||
|
|
||
| rental.set_checkout_date |
There was a problem hiding this comment.
I like the idea of making set_checkout_date be its own method. If you were to take this even further, you could write a class method on Rental that does both in one step.
|
|
||
| def checkin | ||
| rental = Rental.find_by(movie_id: rental_params[:movie_id], customer_id: rental_params[:customer_id]) | ||
|
|
There was a problem hiding this comment.
I don't see that using strong params here gets you anything. It would be simpler to say:
Rental.find_by(movie_id: params[:movie_id], customer_id: params[:customer_id])Since we're not using params directly to create or update a model (as in Rental.new(params)), we don't need the filtering that strong params gives us.
| def movies_checked_out_count | ||
| currently_rented = Rental.where(customer_id: self.id, currently_checked_out: true) | ||
| return currently_rented.length | ||
| end |
There was a problem hiding this comment.
Because you have the relation on line 2, you could shorten line 14 to rentals.where(currently_checked_out: true).
There was a problem hiding this comment.
I do love that you calculate this value on the fly instead of storing it in the database. That means there's no way to forget to update the count.
| def available_inventory | ||
| checked_out_movies = Rental.where(movie_id: self.id, currently_checked_out: true) | ||
| avail_inventory = inventory - checked_out_movies.length | ||
| return avail_inventory |
There was a problem hiding this comment.
Similar comments to Customer#movies_checked_out_count
|
|
||
| it "returns json" do | ||
| # Arrange - Act | ||
| get customers_path |
There was a problem hiding this comment.
The code you've written here matches what we showed in class. However, those tests were intentionally split out as a pedagogical tool. I think you could get away with collapsing all of these into one, since there's only one behavior you're covering.
|
|
||
| get movie_path(invalid_movie_id) | ||
|
|
||
| must_respond_with :bad_request |
There was a problem hiding this comment.
Since your endpoint returns specific JSON in this case, it would be wise to verify that is sent correctly.
Video Store API
Congratulations! You're submitting your assignment!
If you didn't get to the functionality the question is asking about, reply with what you would have done if you had completed it.
Comprehension Questions
POST /rentals/check-inendpoint? What does the time complexity depend on? Explain your reasoning.